Add a test for `--message-format` parsing the mixed output of rustc
authorfmdkdd <fmdkdd@gmail.com>
Fri, 16 Dec 2016 13:16:37 +0000 (14:16 +0100)
committerfmdkdd <fmdkdd@gmail.com>
Fri, 16 Dec 2016 13:46:17 +0000 (14:46 +0100)
tests/build.rs

index e6ae434c5e76e773b9ea5f09fdb9e7050419cf38..7b19633b994c54c8b11365ad062dda49911aa153 100644 (file)
@@ -2470,6 +2470,55 @@ fn wrong_message_format_option() {
 r#"[ERROR] Could not match 'xml' with any of the allowed variants: ["Human", "Json"]"#));
 }
 
+#[test]
+fn message_format_json_forward_stderr() {
+    if is_nightly() { return }
+
+    let p = project("foo")
+        .file("Cargo.toml", &basic_bin_manifest("foo"))
+        .file("src/main.rs", "fn main() { let unused = 0; }");
+
+    assert_that(p.cargo_process("rustc").arg("--bin").arg("foo")
+                .arg("--message-format").arg("JSON").arg("--").arg("-Zno-trans"),
+                execs()
+                .with_stderr_contains("[WARNING] the option `Z` is unstable [..]")
+                .with_json(r#"
+    {
+        "reason":"compiler-message",
+        "package_id":"foo 0.5.0 ([..])",
+        "target":{"kind":["bin"],"name":"foo","src_path":"[..]"},
+        "message":{
+            "children":[],"code":null,"level":"warning","rendered":null,
+            "message":"unused variable: `unused`, #[warn(unused_variables)] on by default",
+            "spans":[{
+                "byte_end":22,"byte_start":16,"column_end":23,"column_start":17,"expansion":null,
+                "file_name":"[..]","is_primary":true,"label":null,"line_end":1,"line_start":1,
+                "suggested_replacement":null,
+                "text":[{
+                    "highlight_end":23,
+                    "highlight_start":17,
+                    "text":"fn main() { let unused = 0; }"
+                }]
+            }]
+        }
+    }
+
+    {
+        "reason":"compiler-artifact",
+        "package_id":"foo 0.5.0 ([..])",
+        "target":{"kind":["bin"],"name":"foo","src_path":"[..]"},
+        "profile":{
+            "debug_assertions":true,
+            "debuginfo":true,
+            "opt_level":"0",
+            "test":false
+        },
+        "features":[],
+        "filenames":["[..]"]
+    }
+"#));
+}
+
 #[test]
 fn no_warn_about_package_metadata() {
     let p = project("foo")